﻿using Huayou.Common;
using Huayou.UI.WebControls;
using HySoft.Cash.BaseClass;
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using HySoft.Cash.Web;

namespace HySoft.Cash.Web.Manage.Invoices
{

    public class AllInvoice : ParentPage, IRequiresSessionState
    {
        protected Button btnSearch;
        protected Huayou.UI.WebControls.DataGridTable dgdList;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        protected Label lblTip;
        protected TextBox txtFromDate;
        protected TextBox txtInvoiceNo;
        protected TextBox txtOrgName;
        protected TextBox txtParamstr;
        protected TextBox txtToDate;

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.dgdList.DataBind();
        }

        protected void dgdList_CancelCommand(object source, DataGridCommandEventArgs e)
        {
            this.dgdList.EditItemIndex = -1;
            this.dgdList.DataBind();
        }

        protected void dgdList_DataBinding(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            string commandText = "";
            string str2 = "";
            if (!this.txtInvoiceNo.Text.Trim().Equals(""))
            {
                str2 = str2 + " and i.Sid=" + this.txtInvoiceNo.Text.Trim();
            }
            if (!this.txtOrgName.Text.Trim().Equals(""))
            {
                str2 = str2 + " and OrgName='" + this.txtOrgName.Text + "' ";
            }
            if (!this.txtFromDate.Text.Trim().Equals("") && (this.txtFromDate.Text.Trim() != "dd/mm/yyyy"))
            {
                str2 = str2 + " and cast(InvoiceDate as datetime)>='" + this.txtFromDate.Text + "'";
            }
            if (!this.txtToDate.Text.Trim().Equals("") && (this.txtToDate.Text.Trim() != "dd/mm/yyyy"))
            {
                str2 = str2 + " and cast(InvoiceDate as datetime)<='" + this.txtToDate.Text + "'";
            }
            commandText = "select i.Sid,i.OrgSid,InvoiceDate,InvoiceAmount,ReceiveAmount,Penalty,InterestCharges,Guid,i.IsValid,OrgName\r\nfrom tInvoiceList i inner join tOrgInfo o\r\non i.OrgSid=o.Sid where i.IsValid!=3 " + str2 + " order by i.Sid desc";
            dt = SqlHelper.ExecuteDataset(ConfigurationManager.AppSettings["SQLConnString"], 1, commandText).Tables[0];
            CommonBasePage.SetPage(this.dgdList, dt);
            base.AddValue("pageno", Convert.ToString((int)(this.dgdList.CurrentPageIndex + 1)));
            this.txtParamstr.Text = base.PackPart(base.ParamValue);
        }

        protected void dgdList_EditCommand(object source, DataGridCommandEventArgs e)
        {
            this.dgdList.EditItemIndex = e.Item.ItemIndex;
            this.dgdList.DataBind();
        }

        protected void dgdList_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            this.dgdList.CurrentPageIndex = e.NewPageIndex;
            this.dgdList.DataBind();
        }

        protected void dgdList_UpdateCommand(object source, DataGridCommandEventArgs e)
        {
            string text = e.Item.Cells[0].Text;
            string str2 = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
            string str3 = ((TextBox)e.Item.Cells[6].Controls[0]).Text;
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@Sid", text), new SqlParameter("@dPenalty", str2), new SqlParameter("@dInterestCharges", str3) };
            SqlHelper.ExecuteNonQuery(ConfigurationManager.AppSettings["SQLConnString"], CommandType.StoredProcedure, "UptPenalty", commandParameters);
            this.dgdList.EditItemIndex = -1;
            this.dgdList.DataBind();
        }

        protected override void OnInit(EventArgs e)
        {
            base.m_ModuleCode = "";
            base.CheckLogin(true);
            base.CheckPerm();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                base.ParamValue = base.UnPack();
                this.txtParamstr.Text = base.PackPart(base.ParamValue);
                string str = base.GetValue("pageno");
                if (str != null)
                {
                    this.dgdList.CurrentPageIndex = Convert.ToInt32(str) - 1;
                }
                this.dgdList.DataBind();
            }
            else
            {
                base.ParamValue = base.UnPackPart(this.txtParamstr.Text);
            }
        }

        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }
}
